/**
 * 功能请求相关API
 */
import { apiClient, API_ENDPOINTS } from './index'
import type { ApiResponse } from './types/common'
import type {
  FeatureRequestQueryParams,
  FeatureRequestSubmitParams,
  FeatureRequestsResponse,
  FeatureRequestDetail as FeatureRequestDetailResponse,
  FeatureStatusStats as FeatureStatusResponse,
  FeatureVoteResponse,
  FeatureRequestSubmitResponse
} from './types/feature'

/**
 * 获取功能请求列表
 * @param params 查询参数，status为字符串数组，sort为后端支持的四种字符串
 * @returns Promise
 */
export function getFeatureRequests(params: FeatureRequestQueryParams): Promise<ApiResponse<FeatureRequestsResponse>> {
  return apiClient.get(API_ENDPOINTS.FEATURE_LIST, { params })
}

/**
 * 获取功能请求详情
 * @param id 功能请求ID
 * @returns Promise
 */
export function getFeatureRequestDetail(id: number | string): Promise<ApiResponse<FeatureRequestDetailResponse>> {
  return apiClient.get(API_ENDPOINTS.FEATURE_DETAIL, { params: { id } })
}

/**
 * 提交功能请求
 * @param data 功能请求数据
 * @returns Promise
 */
export function submitFeatureRequest(data: FeatureRequestSubmitParams): Promise<ApiResponse<FeatureRequestSubmitResponse>> {
  return apiClient.post(API_ENDPOINTS.FEATURE_SUBMIT, data)
}

/**
 * 给功能请求投票
 * @param id 功能请求ID
 * @returns Promise
 */
export function voteFeatureRequest(id: number | string): Promise<ApiResponse<FeatureVoteResponse>> {
  return apiClient.post(API_ENDPOINTS.FEATURE_VOTE, { id })
}

/**
 * 获取功能请求状态统计
 * @returns Promise
 */
export function getFeatureRequestsStatus(): Promise<ApiResponse<FeatureStatusResponse>> {
  return apiClient.get(API_ENDPOINTS.FEATURE_STATUS)
} 